package com.cloud.system.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cloud.annex.AnnexUrlService;
import com.cloud.system.entity.ProjectAnnex;
import com.cloud.system.mapper.SysProjectAnnexMapper;
import com.cloud.system.service.ISysProjectAnnexService;
import com.cloud.utils.StringUtils;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 系统附件
 *
 * @author yzj
 * @since 2022-11-30
 */
@Service
public class SysProjectAnnexServiceImpl extends ServiceImpl<SysProjectAnnexMapper, ProjectAnnex> implements ISysProjectAnnexService {

    @Resource
    private SysProjectAnnexMapper sysProjectAnnexMapper;

    @Resource
    private AnnexUrlService annexUrlService;

    /**
     * 系统附件分页
     *
     * @author yzj
     */
    @Override
    public List<ProjectAnnex> selectSysProjectAnnexList(ProjectAnnex projectAnnex) {
        return sysProjectAnnexMapper.selectSysProjectAnnexList(projectAnnex);
    }

    /**
     * 系统附件新增
     *
     * @author yzj
     */
    @Override
    public int insertObject(ProjectAnnex projectAnnex) {
        return sysProjectAnnexMapper.insert(projectAnnex);
    }

    /**
     * 系统附件修改
     *
     * @author yzj
     */
    @Override
    public int updateObject(ProjectAnnex projectAnnex) {
        return sysProjectAnnexMapper.updateById(projectAnnex);
    }

    /**
     * 根据应用项目查询配置列表
     *
     * @param isApply
     * @return
     */
    @Override
    public List<ProjectAnnex> selectApplyProjectAnnex(Integer isApply) {
        return sysProjectAnnexMapper.selectApplyProjectAnnex(isApply);
    }

    /**
     * 根据主键查询附件对象
     *
     * @param annexId
     * @return
     */
    @Override
    public ProjectAnnex selectAnnexInfo(Long annexId) {
        ProjectAnnex projectAnnex = sysProjectAnnexMapper.selectAnnexInfo(annexId);
        if (StringUtils.isNotNull(projectAnnex)) {
            if (StringUtils.isNotEmpty(projectAnnex.getIconUrl())) {
                projectAnnex.setIconUrl(annexUrlService.getImageTurnPath(projectAnnex.getIconUrl()));
            }
            if (StringUtils.isNotEmpty(projectAnnex.getAnnexUrl())) {
                projectAnnex.setAnnexUrl(annexUrlService.getAnnexTurnPath(projectAnnex.getAnnexUrl()));
            }
        }
        return projectAnnex;
    }

}
